package com.blrs.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.blrs.VO.ClassVO;
import com.blrs.common.annotation.RepeatSubmit;
import com.blrs.common.constant.HttpStatus;
import com.blrs.common.core.domain.entity.SysUser;
import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.domain.HonorManagement;
import com.blrs.service.enterprise.electric.IElectricSalesInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.ElectricSalesInfo;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 电销管理信息Controller
 * 
 * @author ruoyi
 * @date 2023-08-11
 */
@RestController
@RequestMapping("/electric/electric")
public class ElectricSalesInfoController extends BaseController
{
    @Autowired
    private IElectricSalesInfoService electricSalesInfoService;

    /**
     * 查询电销管理信息列表
     */
    //@PreAuthorize("@ss.hasPermi('electric:electric:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElectricSalesInfo electricSalesInfo, @RequestParam Integer pageNum, @RequestParam Integer pageSize)
    {
       // startPage();
        List<ElectricSalesInfo> list = electricSalesInfoService.selectElectricSalesInfoList(electricSalesInfo);
        int start = (pageNum - 1) * pageSize;
        int end = Math.min(start + pageSize, list.size());
        List<ElectricSalesInfo> electricSalesInfos = list.subList(start, end);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(electricSalesInfos);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
       // return getDataTable(list);
    }

    /**
     * 查询电话管理信息前15条数据
     */
    @GetMapping("/listByIndex")
    public List listByIndex(){
       final ElectricSalesInfo electricSalesInfo = new ElectricSalesInfo();
        List<ElectricSalesInfo> list = electricSalesInfoService.selectElectricSalesInfoListByIndex(electricSalesInfo);
        return list;
    }

    /**
     * 人员管理查询电销数据
     */


    /**
     * 导出电销管理信息列表
     */
    //@PreAuthorize("@ss.hasPermi('electric:electric:export')")
    @Log(title = "电销管理信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElectricSalesInfo electricSalesInfo)
    {
        List<ElectricSalesInfo> list = electricSalesInfoService.selectElectricSalesInfoList(electricSalesInfo);
        ExcelUtil<ElectricSalesInfo> util = new ExcelUtil<ElectricSalesInfo>(ElectricSalesInfo.class);
        util.exportExcel(response, list, "电销管理信息数据");
    }

    /**
     * 获取电销管理信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('electric:electric:query')")
    @GetMapping(value = "/{electricId}")
    public AjaxResult getInfo(@PathVariable("electricId") String electricId)
    {
        return success(electricSalesInfoService.selectElectricSalesInfoByElectricId(electricId));
    }

    /**
     * 新增电销管理信息
     */
    //@PreAuthorize("@ss.hasPermi('electric:electric:add')")
    @Log(title = "电销管理信息", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit(interval = 3000)
    public AjaxResult add(@RequestBody ElectricSalesInfo electricSalesInfo) throws NoSuchFieldException, IllegalAccessException {
        return toAjax(electricSalesInfoService.insertElectricSalesInfo(electricSalesInfo));
    }

    /**
     * 修改电销管理信息
     */
    //@PreAuthorize("@ss.hasPermi('electric:electric:edit')")
    @Log(title = "电销管理信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElectricSalesInfo electricSalesInfo) throws NoSuchFieldException, IllegalAccessException {
        return electricSalesInfoService.updateElectricSalesInfo(electricSalesInfo);
    }

    /**
     * 删除电销管理信息
     */
    //@PreAuthorize("@ss.hasPermi('electric:electric:remove')")
    @Log(title = "电销管理信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{electricIds}")
    public AjaxResult remove(@PathVariable String[] electricIds)
    {
        return toAjax(electricSalesInfoService.deleteElectricSalesInfoByElectricIds(electricIds));
    }

    /**
     * 查询电销类型
     */
    //@PreAuthorize("@ss.hasPermi('electric:electric:list')")
    @GetMapping("/electricType")
    public AjaxResult getElectricType(){
        return success(electricSalesInfoService.selectElectricType());
    }
    /**
     * 公海转电销
     */
    //@PreAuthorize("@ss.hasPermi('electric:electric:convert')")
    @DeleteMapping("/convert/{ids}/{deptId}")
    public AjaxResult convert(@PathVariable String[] ids,@PathVariable String deptId) throws NoSuchFieldException, IllegalAccessException {
        return electricSalesInfoService.convertElectric(ids,deptId);
    }
    @Log(title = "批量修改主分类", businessType = BusinessType.UPDATE)
    //@PreAuthorize("@ss.hasPermi('qualificationInfo:qualification:import')")
    @PostMapping("/updateClass")
    public AjaxResult updateClass(@RequestBody ClassVO classVO) throws Exception
    {
        electricSalesInfoService.updateClassIds(classVO.getEnterIds(),classVO.getClassId());
        return success("修改成功");
    }

    @PostMapping("/editBusinessManager")
    public AjaxResult editBusinessManager(@RequestBody ClassVO classVO) {
        return toAjax(electricSalesInfoService.editBusinessManager(classVO));
    }
    @Log(title = "退回")
    @GetMapping("/return/{id}")
    public AjaxResult returnEle(@PathVariable(name = "id")String id){
        return toAjax(electricSalesInfoService.returnEle(id));
    }

    //电销转商机
    @GetMapping("/convert/{electricId}")
    public AjaxResult convert(@PathVariable(name = "electricId")String electricId){
        return electricSalesInfoService.convertBusinessInfo(electricId);
    }

    /**
     * 查询该公司所有的电销记录
     */
    @GetMapping("/personList")
    public TableDataInfo personList(ElectricSalesInfo electricSalesInfo)
    {
        startPage();
        List<ElectricSalesInfo> list = electricSalesInfoService.selectElectricSalesInfoListByPerson(electricSalesInfo);
        return getDataTable(list);
    }
    /**
     * 查询所有的电销人员
     */
    @GetMapping("/personListAll")
    public  List<SysUser> elePersonListAll(){
        return electricSalesInfoService.selectElectricSalesPersonList();
    }

}
